package cz.muni.fi.pa165.pa165_spring.dao;

import cz.muni.fi.pa165.pa165_spring.model.Player;
import java.util.Collection;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.springframework.stereotype.Repository;

@Repository
public class PlayerDAO
{
    @PersistenceContext(name = "TestPU")
    private EntityManager em;
    
    public void create(Player player) {
        em.persist(player);
    }

    public Player getById(Long id) {
        Player player = em.find(Player.class, id);
        return player;
    }

    public Collection<Player> findAll() {
        Query query = em.createQuery("SELECT p FROM Player p");
        Collection<Player> allPlayers = query.getResultList();
        return allPlayers;
    }
}
